package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.happy.cat.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.SocialTrans;
import com.happy.cat.project.system.service.ISocialTransService;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.happy.cat.framework.web.page.TableDataInfo;

/**
 * 交易流水Controller
 *
 * @author verne
 * @date 2020-08-29
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/socialTrans" )
@Api("交易流水 API")
public class SocialTransController extends BaseController {

    private final ISocialTransService iSocialTransService;

    /**
     * 查询交易流水列表
     */
    @ApiOperation(value = "查询交易流水列表",notes = "查询交易流水列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:socialTrans:list')")
    @GetMapping("/list")
    public TableDataInfo list(SocialTrans socialTrans)
    {
        startPage();
        LambdaQueryWrapper<SocialTrans> lqw = new LambdaQueryWrapper<SocialTrans>();
        if (StringUtils.isNotBlank(socialTrans.getTransNo())){
            lqw.eq(SocialTrans::getTransNo ,socialTrans.getTransNo());
        }
        if (StringUtils.isNotBlank(socialTrans.getTransType())){
            lqw.eq(SocialTrans::getTransType ,socialTrans.getTransType());
        }
        if (StringUtils.isNotBlank(socialTrans.getRoomId())){
            lqw.eq(SocialTrans::getRoomId ,socialTrans.getRoomId());
        }
        if (StringUtils.isNotBlank(socialTrans.getRoomName())){
            lqw.like(SocialTrans::getRoomName ,socialTrans.getRoomName());
        }
        if (socialTrans.getPayUserId() != null){
            lqw.eq(SocialTrans::getPayUserId ,socialTrans.getPayUserId());
        }
        if (socialTrans.getPayAccountId() != null){
            lqw.eq(SocialTrans::getPayAccountId ,socialTrans.getPayAccountId());
        }
        if (socialTrans.getReceiveUserId() != null){
            lqw.eq(SocialTrans::getReceiveUserId ,socialTrans.getReceiveUserId());
        }
        if (socialTrans.getReceiveAccountId() != null){
            lqw.eq(SocialTrans::getReceiveAccountId ,socialTrans.getReceiveAccountId());
        }
        if (socialTrans.getPayAmount() != null){
            lqw.eq(SocialTrans::getPayAmount ,socialTrans.getPayAmount());
        }
        if (StringUtils.isNotBlank(socialTrans.getPayAmountType())){
            lqw.eq(SocialTrans::getPayAmountType ,socialTrans.getPayAmountType());
        }
        if (socialTrans.getReceiveAmount() != null){
            lqw.eq(SocialTrans::getReceiveAmount ,socialTrans.getReceiveAmount());
        }
        if (StringUtils.isNotBlank(socialTrans.getReceiveAmountType())){
            lqw.eq(SocialTrans::getReceiveAmountType ,socialTrans.getReceiveAmountType());
        }
        if (socialTrans.getPayTime() != null){
            lqw.eq(SocialTrans::getPayTime ,socialTrans.getPayTime());
        }
        if (StringUtils.isNotBlank(socialTrans.getPayChannel())){
            lqw.eq(SocialTrans::getPayChannel ,socialTrans.getPayChannel());
        }
        if (StringUtils.isNotBlank(socialTrans.getExtra1())){
            lqw.eq(SocialTrans::getExtra1 ,socialTrans.getExtra1());
        }
        if (StringUtils.isNotBlank(socialTrans.getExtra2())){
            lqw.eq(SocialTrans::getExtra2 ,socialTrans.getExtra2());
        }
        if (StringUtils.isNotBlank(socialTrans.getExtra3())){
            lqw.eq(SocialTrans::getExtra3 ,socialTrans.getExtra3());
        }
        List<SocialTrans> list = iSocialTransService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出交易流水列表
     */
    @ApiOperation(value = "导出交易流水列表",notes = "导出交易流水列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:socialTrans:export')" )
    @Log(title = "交易流水" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(SocialTrans socialTrans) {
        LambdaQueryWrapper<SocialTrans> lqw = new LambdaQueryWrapper<SocialTrans>(socialTrans);
        List<SocialTrans> list = iSocialTransService.list(lqw);
        ExcelUtil<SocialTrans> util = new ExcelUtil<SocialTrans>(SocialTrans. class);
        return util.exportExcel(list, "socialTrans" );
    }

    /**
     * 获取交易流水详细信息
     */
    @ApiOperation(value = "获取交易流水详细信息",notes = "获取交易流水详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:socialTrans:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iSocialTransService.getById(id));
    }

    /**
     * 新增交易流水
     */
    @ApiOperation(value = "新增交易流水",notes = "新增交易流水",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:socialTrans:add')" )
    @Log(title = "交易流水" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SocialTrans socialTrans) {
        return toAjax(iSocialTransService.save(socialTrans) ? 1 : 0);
    }

    /**
     * 修改交易流水
     */
    @ApiOperation(value = "修改交易流水",notes = "修改交易流水",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:socialTrans:edit')" )
    @Log(title = "交易流水" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SocialTrans socialTrans) {
        return toAjax(iSocialTransService.updateById(socialTrans) ? 1 : 0);
    }

    /**
     * 删除交易流水
     */
    @ApiOperation(value = "删除交易流水",notes = "删除交易流水",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:socialTrans:remove')" )
    @Log(title = "交易流水" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iSocialTransService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
